import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
export const Layout = () => import('@/views/layout/index.vue')
// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: '/redirect',
    component: Layout,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index.vue')
      }
    ]
  },
  {
    path: '/',
    name: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        name: 'Dashboard' // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
      },
      {
        path: 'form',
        component: () => import('@/views/dashboard/form.vue'),
        name: 'form'
      },
      {
        path: 'table',
        component: () => import('@/views/dashboard/table.vue'),
        name: 'Table'
      }
    ]
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/errorPage/404.vue')
  }
]
/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes as RouteRecordRaw[],
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 })
})
/** * 重置路由 */
export function resetRouter () {
  router.replace({ path: '/login' })
}
export default router
